package com.wanwu.channel.remote.allinpay.TLHttpUtils;


import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.time.Instant;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;

public class MiscUtils {
    private static final DateTimeFormatter FSDTF = DateTimeFormatter.ofPattern("yyyyMMddHHmmss").withZone(ZoneOffset.UTC);
    private static final DateTimeFormatter MSDTF = DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS").withZone(ZoneOffset.UTC);

    private MiscUtils() {
    }

    public static String dtUTC() {
        return FSDTF.format(Instant.now());
    }

    public static String randId() {
        return MiscUtils.msUTC() + (int) Math.random() * 100;
    }

    public static String msUTC() {
        return MSDTF.format(Instant.now());
    }

    public static boolean isEmpty(String s) {
        return s == null || "".equals(s);
    }

    public static String uri(Class<?> clz) {
    	/*GcpReqClz ann=clz.getAnnotation(GcpReqClz.class);
    	if(ann==null) return null;
    	return ann.value();*/
        return null;
    }

    public static String join(String[] array, char separator) {
        StringBuilder buf = new StringBuilder(array.length * 16);

        for (int i = 0; i < array.length; i++) {
            if (i > 0) buf.append(separator);
            if (array[i] != null) {
                buf.append(array[i]);
            }
        }
        return buf.toString();
    }

    public static int copy(InputStream in, OutputStream out) throws IOException {
        int byteCount = 0;
        byte[] buffer = new byte[4096];
        int bytesRead = -1;
        while ((bytesRead = in.read(buffer)) != -1) {
            out.write(buffer, 0, bytesRead);
            byteCount += bytesRead;
        }
        out.flush();
        return byteCount;
    }

    public static byte[] copyToByteArray(InputStream in) throws IOException {
        if (in == null) return new byte[0];
        ByteArrayOutputStream out = new ByteArrayOutputStream(4096);
        copy(in, out);
        return out.toByteArray();
    }

}
